package com.ljf.service.impl;

import java.util.List;
import java.util.Properties;

import com.ljf.dao.IUserDao;
import com.ljf.entity.User;
import com.ljf.service.IUserService;

public class UserServiceImpl implements IUserService  {

	private IUserDao ud;

	@Override
	public User login(User u) {
		Properties prop = new Properties();
		prop.setProperty("username", u.getUsername());
		prop.setProperty("password", u.getPassword());
		List<User> users =ud.find(prop);
		
		if(users.isEmpty()){
			ud.add(u);
			return null;
		}else{
			return users.get(0);
		}
	}

	@Override
	public boolean regist(User u) {
		Properties prop = new Properties();
		prop.setProperty("username", u.getUsername());
		List<User> users = ud.find(prop);
		if (users.isEmpty()){
			ud.add(u);
			return true;
		}else{
			return false;
		}
	}

	public IUserDao getUd() {
		return ud;
	}

	public void setUd(IUserDao ud) {
		this.ud = ud;
	}
}
